package com.cskaoyan.controller.mallController;

import com.cskaoyan.model.bean.Issue;
import com.cskaoyan.model.bo.PageBo;
import com.cskaoyan.model.bo.mall.IssueCreatBo;
import com.cskaoyan.model.bo.mall.DeleteByIdVo;
import com.cskaoyan.model.vo.BaseRespVo;
import com.cskaoyan.model.vo.mall.IssueVo;
import com.cskaoyan.service.mall.MallAfterOrderService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/admin/issue")
@RestController
@RequiresPermissions("admin:issue:*")
public class MallIssueController {

    @Autowired
    MallAfterOrderService mallAfterOrderService;

    @RequestMapping("/list")
    public BaseRespVo getIssueList(PageBo pageBo, String question) {
        IssueVo issueVoList = mallAfterOrderService.getIssueList(pageBo, question);
        return BaseRespVo.ok(issueVoList);
    }

    @PostMapping("/create")
    public BaseRespVo issueCeat(@RequestBody IssueCreatBo issueCreatBo) {
        Issue issue = mallAfterOrderService.issueCreat(issueCreatBo);

        return BaseRespVo.ok(issue);
    }

    @PostMapping("/delete")
    public BaseRespVo issueDelete(@RequestBody DeleteByIdVo deleteByIdVo) {

        int i = mallAfterOrderService.issueDelete(deleteByIdVo.getId());
        if (i == 1) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.error(402, "删除失败");
    }

    @PostMapping("/update")
    public BaseRespVo issueDelete(@RequestBody Issue issue) {

        int i = mallAfterOrderService.issueUpdate(issue);
        if (i == 1) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.error(402, "更新失败");
    }
}
